﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Erau;

namespace ErauConsole
{
	public partial class ConsoleForm : Form, IErauConsole
	{
		public ConsoleForm()
		{
			InitializeComponent();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			EraTable t = ErauEngine.Instance.GameData;

			// 테스트값을 넣어보자.
			t["테스트1"] = 1;
			t["123"] = 1.23;
			t["yyy"] = "ㅌㅌㅌㅌㅌ";
			
			t["CHARA"] = new EraTable();
			t["CHARA"]["이름"] = "테스터";
			t["CHARA"]["HP"] = 100;

			t["CHARA"]["관계"] = new EraTable();
			t["CHARA"]["관계"]["캐릭터1"] = new EraTable();
			t["CHARA"]["관계"]["캐릭터1"]["aaa"] = 3.21;

            ErauEngine.Instance.Save(0);

            print_var(ErauEngine.Instance.GameData);

            testTextBox.Text += "\r\n\r\n";

            ErauEngine.Instance.Load(0);

            print_var(ErauEngine.Instance.GameData);
		}

		void print_var(EraVar v)
		{
			if (v is EraTable)
			{
				testTextBox.Text += "ARRAY\r\n";
				foreach (KeyValuePair<string, EraVar> p in ((EraTable)v).Table)
				{
					testTextBox.Text += p.Key + " : ";
					print_var(p.Value);
				}

			}
			else
			{
				testTextBox.Text += v.ToString() + "(" + v.GetType().ToString() + ")\r\n";
			}
		}

		public void Print(string msg)
		{
			testTextBox.Text += msg;
		}

	}
}
